package org.theSeed.base.pojo.sysEnum;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

/**
 * 系统默认错误码
 */
public enum  SysCode {
    HTTP_NOT_FOUND(404,"资源不存在"),


    //成功响应
    SUCCESS(1200,"成功"),
    //自定义失败，允许的常见失败
    FAIL(1411,"失败"),
    //参数错误
    PARAM_ERR(1400,"参数错误"),
    //未授权
    UN_AUTH(1401,"未授权"),
    //权限不足
    UN_PERMISSON(1403,"权限不足"),
    /**
     * 资源不存在
     */
    UN_RESOURCE(1404,"资源不存在"),
    //资源不存在
    NOT_FOUND(1404,"资源不存在"),
    //客户端多次请求
    MANY_REQUEST(1429,"系统繁忙,请勿频繁请求"),
    //系统未知异常，不允许的常见失败
    UNKNOW_FAIL(1511,"未知异常"),
    ;
    SysCode(Integer code, String describStr) {
        this.code = code;
        this.describStr = describStr;
    }

    /**
     * 编码
     */
    @Getter
    private Integer code;

    /**
     * 描述字符
     */
    @Getter
    private String describStr;

    /**
     * 获取实例
     * @param code
     * @return
     */
    public static SysCode getInstance(Integer code){
        if (ObjectUtil.isNull(code)){
            return null;
        }

        for (SysCode item : values()) {
            if (item.code.equals(code))
                return item;
        }
        return null;
    }
}
